package com.hkd.servlet;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/5/4 22:35
 * @description：
 * @modified By：
 * @version:
 */


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DoLogin extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        String name=req.getParameter("username");
        String pwd=req.getParameter("password");

        if ("zhangsan".equals(name)&&"123".equals(pwd)){
            RequestDispatcher dispatcher=req.getRequestDispatcher("/login/success.jsp");
            dispatcher.forward(req,resp);
        }else {
            req.setAttribute("error","用户名或密码错误");
            RequestDispatcher dispatcher=req.getRequestDispatcher("/login/login.jsp");
            dispatcher.forward(req,resp);
        }
    }
}